package com.fs.ssm004.service.impl;
import com.fs.ssm004.Dao.GradeDao;
import com.fs.ssm004.pojo.Course;
import com.fs.ssm004.pojo.Grade;
import com.fs.ssm004.service.CourseService;
import com.fs.ssm004.service.GradeService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class GradeServiceImpl implements GradeService {
    private GradeDao gradeDao;
    @Autowired //自动装备
    public GradeServiceImpl(GradeDao gradeDao) {
        this.gradeDao = gradeDao;
    }
    @Override
    public List<Grade> getAll() {
        return (List<Grade>) gradeDao.queryAll();
    }
    @Override
    public PageInfo<Grade> getUsersByPage(Integer currentPage, Integer pageSize) {
        //准备拦截mybatis后续的查询
        PageHelper.startPage(currentPage, pageSize);
        List<Grade> gradeList = gradeDao.queryAll();
        System.out.println(gradeList.size());
        //pagehelper内部计算总共有多少页
        PageInfo<Grade> pageInfo = new PageInfo<>(gradeList);
        return pageInfo;
    }

    @Override
    public Grade getoneByCourseId(Integer id) {
        Grade grade =gradeDao.queryById(id);
        System.out.println(grade);
        return grade;
    }

    @Override
    public boolean removeOne(Integer id) {
        int result = gradeDao.deleteById(id);
        return result > 0;
    }

    @Override
    public boolean modifyOne(Grade grade) {
        int result = gradeDao.updateById(grade);
        return result > 0;
    }

    @Override
    public boolean addOne(Grade grade) {
        int result = gradeDao.insertById(grade);
        return  result > 0;
    }

    @Override
    public List<Grade> selectLike(Integer id) {
        return (List<Grade>) gradeDao.selectLike(id);
    }


}
